/**
Nectarine Utility Project is a software interface for the web system 'demovibes'
Copyright (C) 2010  Alexandre LAURENT

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

website: http://code.google.com/p/nectarine-utility-project/
e-mail: lw.demoscene@gmail.com
**/

#include "proxypromptdialog.h"

#include <QDialog>

#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QComboBox>
#include <QLabel>
#include <QLineEdit>
#include <QSpinBox>
#include <QPushButton>

#include <QMessageBox>
#include <QNetworkProxy>

ProxyPromptDialog::ProxyPromptDialog(QWidget *parent) :
    QDialog(parent)
{
    this->setWindowTitle("NUP Proxy prompt");

    pMainGrid = new QVBoxLayout(this);

    pProxyTypeBox = new QComboBox(this);
    pProxyTypeBox->addItem(tr("SOCKS 5 Proxy"),QNetworkProxy::Socks5Proxy);

    pHostGrid = new QHBoxLayout();
    pHostLabel = new QLabel(tr("Server name:"),this);
    pHostInput = new QLineEdit(this);
    pPortBox = new QSpinBox(this);
    pPortBox->setRange(1,65536);

    pLoginGrid = new QHBoxLayout();
    pLoginLabel = new QLabel(tr("Username:"),this);
    pLoginInput = new QLineEdit(this);

    pPasswordGrid = new QHBoxLayout();
    pPasswordLabel = new QLabel(tr("Password:"),this);
    pPasswordInput = new QLineEdit(this);

    pButtonGrid = new QHBoxLayout();
    pOkButton = new QPushButton(tr("Ok"),this);
    pCancelButton = new QPushButton(tr("Cancel"),this);

    pMainGrid->addWidget(pProxyTypeBox,0,Qt::AlignHCenter);
    pMainGrid->addLayout(pHostGrid);
        pHostGrid->addWidget(pHostLabel,0,Qt::AlignLeft);
        pHostGrid->addWidget(pHostInput);
        pHostGrid->addWidget(pPortBox,0,Qt::AlignRight);
    pMainGrid->addLayout(pLoginGrid);
        pLoginGrid->addWidget(pLoginLabel,0,Qt::AlignLeft);
        pLoginGrid->addWidget(pLoginInput);
    pMainGrid->addLayout(pPasswordGrid);
        pPasswordGrid->addWidget(pPasswordLabel,0,Qt::AlignLeft);
        pPasswordGrid->addWidget(pPasswordInput);
    pMainGrid->addLayout(pButtonGrid);
        pButtonGrid->addWidget(pOkButton);
        pButtonGrid->addWidget(pCancelButton);

    connect(pOkButton, SIGNAL(clicked()),this,SLOT(accept()));
    connect(pCancelButton, SIGNAL(clicked()),this,SLOT(reject()));

    qDebug() << "LoginPromptDialog created";
}

ProxyPromptDialog :: ~ProxyPromptDialog(void)
{
    qDebug() << "LoginPromptDialog deleted";
}

void ProxyPromptDialog :: accept(void)
{
    qDebug() << "LoginPromptDialog :: accept";

    if ( !this->pHostInput->text().isEmpty() )
    {
        this->done(QDialog::Accepted);
    }
    else
    {
        QMessageBox::warning(this,tr("Error in the input"),tr("Please enter the name of the server!"));
    }
}
